package com.example.demo.service;

import com.example.demo.dao.WxUserAddressDAO;
import com.example.demo.po.WxUserAddress;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class WxUserAddressService {
    @Autowired
    WxUserAddressDAO wxUserAddressDAO;

    @Transactional
     public boolean save(WxUserAddress wua){
         int i =wxUserAddressDAO.save(wua);
         if(i>0){
             if(wua.getIsIndex()==1){
                 int y = wxUserAddressDAO.isindex(wua);
                 if(y>0)
                     return true;
                 else
                     return false;
             }
            return true;
         } else
             return false;
     }

    @Transactional
    public boolean update(WxUserAddress wua){
        int i =wxUserAddressDAO.update(wua);
        if(i>0){
            if(wua.getIsIndex()==1){
                int y = wxUserAddressDAO.isindex(wua);
                if(y>0)
                    return true;
                else
                    return false;
            }
            return true;
        } else
            return false;
    }
    public boolean del(Integer id){
        int i =wxUserAddressDAO.del(id);
        if(i>0)
            return true;
        else
            return false;
    }
    public List<WxUserAddress> findByParam(WxUserAddress wua){
        List<WxUserAddress> list =wxUserAddressDAO.findByParam(wua);
        return list;
    }

    public WxUserAddress findByuserId(String userId){
        WxUserAddress wua = wxUserAddressDAO.findByuserId(userId);
        return  wua;
    }

    public  WxUserAddress findById(Integer id){
        return  wxUserAddressDAO.findById(id);
    }

}
